<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>广东省传播平台-媒体计划投放量录入页</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
<link href="<%=path%>/js/My97DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
<script type="text/javascript" src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js"></script>	
<script type="text/javascript">
$(function(){
	//selectNav('nav7');
});
//时间对比
function timeCheck(a, b) {
    var arr = a.split("-");
    var starttime = new Date(arr[0], arr[1], arr[2]);
    var starttimes = starttime.getTime();

    var arrs = b.split("-");
    var lktime = new Date(arrs[0], arrs[1], arrs[2]);
    var lktimes = lktime.getTime();

    if (starttimes > lktimes) {
        return false;
    }
    else{
        return true;
     }
}
function doSubmit()
{
		//判断特殊字符
		var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
		//规范数字
		var numReg = /^\d+(\.\d{1,3})?$/;
		//0-100数字
		var numReg2 = /^(?:(?!0\d)\d{1,2}(?:\.\d{1,2})?|100(?:\.0{1,2})?)$/;
		
		//开始时间
		var myDate = new Date();
		var y =myDate.getFullYear();    //获取完整的年份(4位,1970-????)
		var m =myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
		var d =myDate.getDate();
		if(m<10){
			m='0'+m;
		}
		if(d<10){
			d='0'+d;
		}
		var norwDate = '${nowDate}';
		//alert(norwDate);

	
		var returnSource = $.trim($("#returnSource").val());
		var increPro = $.trim($("#increPro").val());
		var promotion = $.trim($("#promotion").val());
		
		if($('#city').val()==0)
		{
			alert('地市不能为空');
			return false;
		}
		if($('#costType').val()==0)
		{
			alert('费用类型不能为空!');
			return false;
		}
		if($("#costSubtype").val()==0)
		{
			alert('费用子类不能为空!');
			return false;
		}
		if($('#dialog_link').val().length==0)
		{
			alert('媒体名称不能为空!');
			return false;
		}

		 if(isNaN($('#fixSourceAmount').val()) || !numReg.test($('#fixSourceAmount').val()))
		{
			alert('固定资源大小必须为数字!');
			return false;
		}		
		if($('#fixSourceAmount').val().length==0)
		{
			alert('固定资源不能为空!');
			return false;
		}
		if($('#fixSourceAmount').val().indexOf(' ')>=0)
		{
			alert('固定资源不能存在空格!');
			return false;
		}
		 if(isNaN($('#floatSourceAmount').val()) || !numReg.test($('#floatSourceAmount').val()))
		{
			alert('浮动资源大小必须为数字!');
			return false;
		}
		if($('#floatSourceAmount').val().length==0)
		{
			alert('浮动资源不能为空!');
			return false;
		}
		if($('#floatSourceAmount').val().indexOf(' ')>=0)
		{
			alert('浮动资源不能存在空格!');
			return false;
		}
		 if(isNaN($('#unPromotionAmount').val())  || !numReg.test($('#unPromotionAmount').val()))
		{
			alert('购买资源大小必须为数字!');
			return false;
		}
		if($('#unPromotionAmount').val().length==0)
		{
			alert('购买资源不能为空!');
			return false;
		}
		if($('#unPromotionAmount').val().indexOf(' ')>=0)
		{
			alert('购买资源不能存在空格!');
			return false;
			
		}
		 if(isNaN($('#promotionAmount').val()) || !numReg.test($('#promotionAmount').val()))
		{
			alert('常规赠送资源大小必须为数字!');
			return false;
		}
		if($('#promotionAmount').val().length==0)
		{
			alert('常规赠送资源不能为空!');
			return false;
		}
		if($('#promotionAmount').val().indexOf(' ')>=0)
		{
			alert('常规赠送资源不能存在空格!');
			return false;
		}
		if($('#promotionUsedRatio').val().length==0)
		{
			alert('常规资源折扣率不能为空!');
			return false;
		}
		if($('#promotionUsedRatio').val().indexOf(' ')>=0)
		{
			alert('常规资源折扣率不能存在空格!');
			return false;
		}
		 if(isNaN($('#promotionUsedRatio').val())|| !numReg2.test($('#promotionUsedRatio').val()))
		{
			alert('常规资源折扣率必须为0~100的数字!');
			return false;
		}
		if($('#increPromotionAmount').val().length==0)
		{
			alert('增量赠送资源不能为空!');
			return false;
		}
		if($('#increPromotionAmount').val().indexOf(' ')>=0)
		{
			alert('增量赠送资源不能存在空格!');
			return false;
		}
		 if(isNaN($('#increPromotionAmount').val())  || !numReg.test($('#increPromotionAmount').val()))
		{
			alert('增量赠送资源必须为数字!');
			return false;
		}
		
		if($('#increPromotionUsedRatio').val().length==0)
		{
			alert('增量资源折扣率不能为空!');
			return false;
		}
		if($('#increPromotionUsedRatio').val().indexOf(' ')>=0)
		{
			alert('增量资源折扣率不能存在空格!');
			return false;
		}
		if(isNaN($('#increPromotionUsedRatio').val())|| !numReg2.test($('#increPromotionUsedRatio').val()))
		{
			alert('增量资源折扣率必须为0~100的数字!');
			return false;
		}
		
		if($('#returnSourceAmount').val().length==0)
		{
			alert('年底一次性返还资源不能为空!');
			return false;
		}
		if($('#returnSourceAmount').val().indexOf(' ')>=0)
		{
			alert('年底一次性返还资源不能存在空格!');
			return false;
		}
		if(isNaN($('#returnSourceAmount').val()) || !numReg.test($('#returnSourceAmount').val()))
		{
			alert('年底一次性返还资源大小必须为数字!');
			return false;
		}
		
		if($('#returnSourceUsedRatio').val().length==0)
		{
			alert('年底一次性返还资源折扣率不能为空!');
			return false;
		}
		if($('#returnSourceUsedRatio').val().indexOf(' ')>=0)
		{
			alert('年底一次性返还资源折扣率不能存在空格!');
			return false;
		}
		
		if(isNaN($('#returnSourceUsedRatio').val())||!numReg2.test($('#returnSourceUsedRatio').val()))
		{
			alert('年底一次性返还资源折扣率必须为0~100的数字!');
			return false;
		}
		if((parseFloat($('#fixSourceAmount').val())+parseFloat($('#floatSourceAmount').val())) !=
			   (parseFloat($('#unPromotionAmount').val())+parseFloat($('#promotionAmount').val())+
			   parseFloat($('#increPromotionAmount').val())+parseFloat($('#returnSourceAmount').val())))
		{
			alert('固定资源和浮动资源之和不等于购买和赠送资源之和，请检查！');
			return false;
		}	
		//有效日期不能为空判断
		if (null==promotion || ''==promotion) {
			alert('常规资源有效期不能为空!');
			return false;
		}
		if (null == increPro || ''== increPro) {
			alert('增量资源有效期不能为空!');
			return false;
		}
		if (null == returnSource || ''==returnSource) {
			alert('返还资源有效期不能为空!');
			return false;
		}	
		if (promotion != '') {//不能小于当前日期起判断
			if (!timeCheck(norwDate, promotion)) {
				alert('常规资源有效期不能小于当前系统时间！');
				return false;
				
			}		
		}
		if (increPro != '') {
			if (!timeCheck(norwDate,increPro)) {
				alert('增量资源有效期不能小于当前系统时间！');
				return false;
			}
		}
		if (returnSource != '') {
		 	if (!timeCheck(norwDate,returnSource)) {
				alert('返还资源有效期不能小于当前系统时间！');
				return false;
			}
		}
		$('#planTotalAmount').attr("value",parseFloat($('#fixSourceAmount').val())+parseFloat($('#floatSourceAmount').val()));
		document.forms[0].action="mediaPlanCountUpdateSecond.action";
		document.forms[0].submit();
		
	
}

function getback()
    {
       
       history.go(-1);
       /*var toType = ${toType}; 
       if(toType=='2')
       {
            doSubmit('mediaPriceAction.action');
       }
       else 
       {
          doSubmit('contractlist.action');
       }*/
    }
</script>
</head>

<body>


<!-- 顶部start -->
<jsp:include page="../common/top.jsp"></jsp:include>
<!-- 顶部end -->


<!-- 顶部start -->
<div id="main">
	<div class="body">
		<!-- 导航菜单 -->
		<jsp:include page="../common/nav.jsp"></jsp:include>
		<!-- 主体 -->
		<form method="post">
		<table class="condition"
						style="font-size: 14px; font-weight: bold; text-align: center; line-height: 27px;">
						<tr>
							<td>
								<a href="#"  style="width: 304px; height: 27px; background-image: url(<%=path%>/images/304ing1.gif); color: #ffffff; display:block; float:left; margin-left:-2px;">
									1.设置投放总量
								</a>
								<a href="#"  style="width: 304px; height: 27px; background-image: url(<%=path%>/images/304notComplete1.gif); color: #ffffff; display:block; float:left; margin-left:-7px;">
									2.设置分阶段投放计划
								</a>
							</td>
						</tr>
		</table>
		<div style="background: url(<%=path%>/images/arrow.gif);width:30px; height: 15px; margin-left:145px;"></div>
		<div class="main_body">
			<div id="add_div">
				<table class="table_add" style="width:100%;">
					<tr>
						<th width="148" style="width:150px;">年份：</th>
						<td width="226" style="width:225px;">
							<input  name="sourcePlanYear.planYear" type="text" class="text" style="width:225px;" value="${sourcePlanYear.planYear}" readonly="readonly"/>						
						</td>
						<th width="77">&nbsp;</th>
						<th width="78">地市：</th>
						<td width="645">
						    <input  name="sourcePlanYear.city" type="text" class="text" style="width:225px;" value="${sourcePlanYear.city}" readonly="readonly"/>	
						</td>
					</tr>
					<tr>
				        <th width="148" style="width:150px;">费用类型：</th>
						<td width="226" style="width:225px;">
						    <input  name="sourcePlanYear.costType" type="text" class="text" style="width:225px;" value="${sourcePlanYear.costType}" readonly="readonly"/>	
						</td>
						<th width="77">&nbsp;</th>
						<th width="148" style="width:150px;">费用子类：</th>
						<td width="226" style="width:225px;">
							<input  name="sourcePlanYear.costSubtype" type="text" class="text" style="width:225px;" value="${sourcePlanYear.costSubtype}" readonly="readonly"/>	
						</td>
						<th width="77">&nbsp;</th>
				    </tr>					
				    <tr>
						<th width="148" style="width:150px;">媒体名称：</th>
						<td width="226" style="width:225px;">
							<input id="dialog_link" name="sourcePlanYear.mediaName" class="text" type="text"  style="width:225px;" value="${sourcePlanYear.mediaName}" readonly="readonly"/>
							<input id="dialog_id" name="sourcePlanYear.mediaID" class="text" type="hidden"  style="width:225px;" value="${sourcePlanYear.mediaID}"/>
						    <input id="dialog_idprice" name="sourcePlanYear.idPrice" class="text" type="hidden"  style="width:225px;" value="${sourcePlanYear.idPrice}"/>
						    <input id="dialog_id_price" name="sourcePlanYear.id_price" class="text" type="hidden"  style="width:225px;" value="${sourcePlanYear.id_price}"/>
						    <input id="dialog_idp" name="sourcePlanYear.id" class="text" type="hidden"  style="width:225px;" value="${sourcePlanYear.id}"/>
						</td>
				    </tr>
				</table>
			  <div id="list_div" style="margin:20px">	
				<table class="table_list" style="width: 100%">
					<tr class="bg1">
						<th rowspan="1">计划投放量总和</th>
						<th rowspan="1">固定资源</th>
						<th rowspan="1">浮动资源</th>
						<th rowspan="1">购买资源</th>
						<th colspan="6">赠送资源</th>
					</tr>
				
					<tr>
						<td rowspan="3"><input style="width: 100px;border-style: none;" type="text" id="planTotalAmount" name="sourcePlanYear.planTotalAmount" readonly="readonly" value="<fmt:formatNumber value="${sourcePlanYear.planTotalAmount}" type="number" pattern="##0.000" />"/></td>
						<td rowspan="3"><input style="width: 100px;" type="text" id="fixSourceAmount" name="sourcePlanYear.fixSourceAmount" value="<fmt:formatNumber value="${sourcePlanYear.fixSourceAmount}" type="number" pattern="##0.000" />"  maxlength='12'/></td>
						<td rowspan="3" ><input style="width: 100px;" type="text" id="floatSourceAmount" name="sourcePlanYear.floatSourceAmount" value="<fmt:formatNumber value="${sourcePlanYear.floatSourceAmount}" type="number" pattern="##0.000" />"  maxlength='12'/></td>
						<td rowspan="3"><input style="width: 100px;" type="text" id="unPromotionAmount" name="sourcePlanYear.unPromotionAmount" value="<fmt:formatNumber value="${sourcePlanYear.unPromotionAmount}" type="number" pattern="##0.000" />"  maxlength='12'/></td>
						<th style='width: 10%;' align='right'>常规赠送金额 &nbsp;</th>
						<td><input style="width: 100px;" type="text" id="promotionAmount" name="sourcePlanYear.promotionAmount" value="<fmt:formatNumber value="${sourcePlanYear.promotionAmount}" type="number" pattern="##0.000" />"  maxlength='12'/></td>
						<th style='width: 10%;' align='right'>增量赠送金额&nbsp;</th>
						<td><input style="width: 100px;" type="text" id="increPromotionAmount" name="sourcePlanYear.increPromotionAmount" value="<fmt:formatNumber value="${sourcePlanYear.increPromotionAmount}" type="number" pattern="##0.000" />" maxlength='12'/></td>
						<th style='width: 12%;' align='right'>年底一次性返还金额&nbsp;</th>
						<td><input style="width: 100px;" type="text" id="returnSourceAmount" name="sourcePlanYear.returnSourceAmount" value="<fmt:formatNumber value="${sourcePlanYear.returnSourceAmount}" type="number" pattern="##0.000" />" maxlength='12'/></td>
					   </tr>
					<tr>
						<th style='width: 10%;' align='right'>常规资源折扣率&nbsp;</th>
						<td><input style="width: 100px;" style="width: 100px;" type="text" id="promotionUsedRatio" name="sourcePlanYear.promotionUsedRatio" value="${sourcePlanYear.promotionUsedRatio}" maxlength='9'/></td>
						<th style='width: 10%;' align='right'>增量资源折扣率&nbsp;</th>
						<td><input style="width: 100px;" type="text" id="increPromotionUsedRatio" name="sourcePlanYear.increPromotionUsedRatio" value="${sourcePlanYear.increPromotionUsedRatio}" maxlength='9'/></td>
						<th style='width: 10%;' align='right'>返还资源折扣率&nbsp;</th>
						<td><input style="width: 100px;" type="text" id="returnSourceUsedRatio" name="sourcePlanYear.returnSourceUsedRatio" value="${sourcePlanYear.returnSourceUsedRatio}" maxlength='9'/></td>
					</tr>
					<tr>
						<th style='width: 10%;' align='right'>常规资源有效期&nbsp;</th>
						<td> <input type='text' id='promotion' class='text Wdate' name='sourcePlanYear.promotionAmountTime' id='contractStartTime' value='${fn:substring(sourcePlanYear.promotionAmountTime,0,10)}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>
						<th style='width: 10%;' align='right'>增量资源有效期&nbsp;</th>
						<td> <input type='text' id='increPro' class='text Wdate' name='sourcePlanYear.increPromotionAmountTime' id='contractStartTime'  value='${fn:substring(sourcePlanYear.increPromotionAmountTime,0,10)}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>
						<th style='width: 10%;' align='right'>返还资源有效期&nbsp;</th>
						<td> <input type='text' id='returnSource' class='text Wdate' name='sourcePlanYear.returnSourceAmountTime' id='contractStartTime'  value='${fn:substring(sourcePlanYear.returnSourceAmountTime,0,10)}'  onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>
					</tr>
			  </table> 	
			</div>
		</div>
		<div style="margin:8px 0 0 150px;">
				<input type="button" class="btn-title" value="下一步" onclick="doSubmit()"/>
				&nbsp;&nbsp;
				<input type="button" class="btn-title" value="   返回   " onclick="getback();"/>
	   </div>
	</div>
  </form>	
 </div>
</div>
<!-- 顶部end -->


<!-- 底部start -->
<div id="bottom">
	<div class="body">
		<label>版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动</label>
	</div>
</div>
<!-- 底部end -->
</body>
</html>